<% add_decidim_page_title(t("title", scope: "decidim.initiatives.edit")) %>

<%= render layout:"layouts/decidim/shared/layout_center" do %>
  <div class="text-center py-10">
    <h1 class="title-decorator inline-block text-left"><%= t("title", scope: "decidim.initiatives.edit") %></h1>
  </div>

  <%= decidim_form_for @form, url: initiative_path(current_initiative, locale: current_locale), html: { class: "form__wrapper edit_initiative" } do |f| %>
    <%= render partial: "form", object: f %>

    <div class="form__wrapper-block flex-col-reverse md:flex-row justify-between">
      <%= link_to :back, class: "button button__sm md:button__lg button__text-secondary" do %>
        <%= icon "arrow-left-line", class: "fill-current" %>
        <%= t("back", scope: "decidim.initiatives.edit") %>
      <% end %>
      <%= f.submit t("update", scope: "decidim.initiatives.edit"), class: "button button__sm md:button__lg button__secondary" if allowed_to? :update, :initiative, initiative: current_initiative %>

      <% if allowed_to? :publish, :initiative, initiative: current_initiative %>
        <%= link_to t("actions.publish", scope: "decidim.admin"),
                    publish_initiative_path(current_initiative),
                    method: :post,
                    class: "button button__sm md:button__lg button__secondary",
                    data: { confirm: t("confirm", scope: "decidim.initiatives.edit") } %>
      <% end %>

      <% if allowed_to? :unpublish, :initiative, initiative: current_initiative %>
        <%= link_to t("actions.unpublish", scope: "decidim.admin"),
                    unpublish_initiative_path(current_initiative),
                    method: :delete,
                    class: "button button__sm md:button__lg button__secondary",
                    data: { confirm: t("confirm", scope: "decidim.initiatives.edit") } %>
      <% end %>

      <% if allowed_to? :accept, :initiative, initiative: current_initiative %>
          <%= link_to t("accept", scope: "decidim.initiatives.edit"),
                      accept_initiative_path(current_initiative),
                      method: :post,
                      class: "button button__sm md:button__lg button__secondary",
                      data: { confirm: t("confirm", scope: "decidim.initiatives.edit") } %>
      <% end %>

      <% if allowed_to? :reject, :initiative, initiative: current_initiative %>
          <%= link_to t("reject", scope: "decidim.initiatives.edit"),
                      reject_initiative_path(current_initiative),
                      method: :delete,
                      class: "button button__sm md:button__lg button__secondary",
                      data: { confirm: t("confirm", scope: "decidim.initiatives.edit") } %>
      <% end %>

      <% if allowed_to? :discard, :initiative, initiative: current_initiative %>
        <%= link_to t("discard", scope: "decidim.initiatives.edit"),
                    discard_initiative_path(current_initiative, locale: current_locale),
                    method: :delete,
                    class: "button button__sm md:button__lg button__secondary",
                    data: { confirm: t("confirm", scope: "decidim.initiatives.edit") } %>
      <% end %>

      <% if allowed_to? :export_votes, :initiative, initiative: current_initiative %>
        <%= link_to t("export_votes", scope: "decidim.initiatives.edit"),
                    export_votes_initiative_path(current_initiative, format: :csv),
                    class: "button button__sm md:button__lg button__secondary",
                    data: { confirm: t("confirm", scope: "decidim.initiatives.edit") } %>
      <% end %>

      <% if allowed_to? :export_pdf_signatures, :initiative, initiative: current_initiative %>
        <%= link_to t("export_pdf_signatures", scope: "decidim.initiatives.edit"),
                    export_pdf_signatures_initiative_path(current_initiative, format: :pdf),
                    class: "button button__sm md:button__lg button__secondary",
                    data: { confirm: t("confirm", scope: "decidim.initiatives.edit") } %>
      <% end %>
    </div>
  <% end %>
<% end %>
